<template>
  <el-dialog v-model="show" title="编辑客户" @close="emit('close')">
    <el-form ref="form" :model="editForm" label-width="100px">
      <el-form-item label="客户">
        <el-input v-model="editForm.UserName" placeholder="客户"></el-input>
      </el-form-item>
      <el-form-item label="省份">
        <el-input v-model="editForm.Province" placeholder="省份"></el-input>
      </el-form-item>
      <el-form-item label="城市">
        <el-input v-model="editForm.City" placeholder="城市"></el-input>
      </el-form-item>
      <el-form-item label="县/区">
        <el-input v-model="editForm.Country" placeholder="县/区"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="emit('close')">取消</el-button>
        <el-button type="primary" @click="handleAddrEdit"> 确定 </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ElMessage, ElMessageBox } from "element-plus";
import { ref, watch } from "vue";
import { cityOptions } from "../../../../../utils/city";
const props = defineProps({
  openModal: {
    type: Boolean,
    default: false,
  },
  update: Boolean,
  data: Object,
});

const emit = defineEmits(["close", "reload"]);
const openEditModal = ref(false);
const show = ref(false)
const logisticsAddresses = ref([{}]);
const editForm = ref({
  UserName: "",
  code: "",
  phone: "",
  tel: "",
  fax: "",
  address: "",
  addrDetail: "",
  habit: "",
  agentBrand: "",
  remark: "",
  orderTaker: "",
  businessman: "",
  active: "",
  alarm: "",
  businessLicense: "",
});

const activeTab = ref(1);
watch(
  () => props.openModal,
  (val) => {
    show.value = val
    if (val) {
      if (props.update) {
        editForm.value = props.data;
        editForm.value.address = [
          editForm.value.Province,
          editForm.value.City,
          editForm.value.Country,
        ];
      } else {
        for (let key in editForm.value) {
          editForm.value[key] = null;
        }
      }
    }
  }
);

function handleAddrEdit() {
  emit("reload", editForm.value, props.update);
  emit("close");
}
</script>